package org.kisekiproject.classlibrary {
	import flash.system.ApplicationDomain;

	/**
	 * A class library containing the classes of the local swf.
	 */
	public class LocalClassLibrary implements IClassLibrary {

		/**
		 * Constructor.
		 */
		public function LocalClassLibrary() {
		}

		/**
		 * Get class.
		 */
		public function getClass(name:String):Class {
			if (!ApplicationDomain.currentDomain.hasDefinition(name))
				throw new Error("Class does not exist: "+name);
			
			var cls:Class=Class(ApplicationDomain.currentDomain.getDefinition(name));

			if (!cls)
				throw new Error("Class not found, or not a class: "+name);

			return cls;
		}

		/**
		 * Does the class exist?
		 */
		public function hasClass(name:String):Boolean {
			return ApplicationDomain.currentDomain.hasDefinition(name);
		}
	}
}